<template>
  <el-dialog
      @close="handleDialogClose"
      destroy-on-close
      title="设备验证"
      :close-on-click-modal="false"
      :visible="devFlag"
      :append-to-body="true"
      width="470px"
  >
    <el-form
        ref="form"
        :model="form"
        label-width="120px"
        inline
        label-position="right"
        class="form-container"
        :rules="rules"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="form.password" clearable type="password" show-password autocomplete="new-password"></el-input>
      </el-form-item>
    </el-form>
    <section style="text-align: center;">
      <el-button size="small" @click="handleDialogClose">取消</el-button>
      <el-button size="small" type="primary" :loading="saveLoading" @click="hanldeConfirm">确定</el-button>
    </section>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      rules: {
        username: [
          {required: true, message: '不能为空', trigger: 'blur'},
          {max: 24, message: '长度最大 24 个字符', trigger: 'blur' }
        ],
        password: [
          {required: true, message: '不能为空', trigger: 'blur'},
          {max: 24, message: '长度最大 24 个字符', trigger: 'blur' }
        ],
      },
      saveLoading:false,
      form: {
        username: "",
        password:"",
      },
    };
  },
  props: {
    devFlag: {
      type: Boolean,
      default: false
    },
    editTableRow: {
      type: Object,
      default: ()=>{
        return {}
      },
    }
  },
  computed: {
  },
  watch: {},
  methods: {
    handleDialogClose() {
      // 关闭dialog时，清空表单数据
      this.$refs.form.resetFields();
      // this.$parent.devFlag=false;
      // this.devFlag=false
      this.$emit('update:devFlag',false)
    },
    hanldeConfirm(){
      // console.log(123, this.form);
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log('下一步',this.form);
          var params=JSON.parse(JSON.stringify(this.form))
          console.log(135, params);
          // this.editTableRow = params;
          // this.$parent.devFlag=false;
          this.$emit('handleUpdate', params)
          // 修改成功
          this.W.$tips("success", this.i18n.t('Successfully saved'));
          // 更新父页面表格
          this.handleDialogClose()
          // this.$parent.submitTopForm()

        } else {
          return false;
        }
      })
    },
  },
  mounted(){
    // debugger
    if (this.handleType=='edit'){
      this.form=JSON.parse(JSON.stringify(this.tableRow))
      console.log(this.form);
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep.form-container {
  .el-form-item {
    display: inline-flex;
    .el-form-item__label {
      width: 115px !important;
    }
    .el-input {
      width: 260px;
    }
  }
}
</style>

